package Operation;

import Book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList booklist) {

        System.out.println("归还图书");
        int choic = 1;
        Scanner scanner = new Scanner(System.in);
        System.out.println("立刻查找图书");
        while(choic==1) {
            System.out.println("请输入你要归还书的名字》");
            String name = scanner.nextLine();
            int tail = 0;
            int i = 0;
            for (i = 0; i < booklist.getUsedSize(); i++) {
                if (name.equals(booklist.getName(i))) {
                    tail = i;
                    break;
                }
            }
            if (i == booklist.getUsedSize()) {
                System.out.println("找不到这本书，抱歉这本书不是我们图书馆的");
            } else {
                if (booklist.getBook(tail).getIsBorrowed() == false) {
                    booklist.getBook(tail).setBorrowed();
                    System.out.println("成功归还！");

                } else {
                    System.out.println("抱歉，书架上有这本书,你这本书不是我们图书馆的");
                }
            }
            System.out.println("是否继续添加》  1》继续   0》停止  输入其他数字》停止");
            choic = scanner.nextInt();
        }
    }
}
